#include <stdio.h>  
  
void ThreeFiles(const char* file1, const char* file2, const char* file3) 
{  
    FILE *fp1 = fopen(file1, "w");  
    FILE *fp2 = fopen(file2, "r");  
    FILE *fp3 = fopen(file3, "r");  
  
    if (fp1 == NULL || fp2 == NULL || fp3 == NULL) 
    {  
        printf("打开文件失败!\n");
        return;  
    }  
  
    
    
    // 清空file1  
  
    // 写入file2的内容到file1  
    char buf[1024];  
    for (int i = 0; fgets(buf, 1024, fp2) != NULL; i++)   
    {    
        fputs(buf, fp1);    
    } 

    // 写入file3的内容到file1（追加）
    for (int i = 0; fgets(buf, 1024, fp3) != NULL; i++)   
    {    
        fputs(buf, fp1);    
    }
  
    fclose(fp1);  
    fclose(fp2);  
    fclose(fp3);  
}  
  
int main(int argc, char const *argv[])
{
    ThreeFiles("file1.txt", "file2.txt", "file3.txt"); 
    return 0;
}
